import { BasicColumn, FormSchema } from '/@/components/Table';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';
import { apiGetCustomDropdown } from '@/api/http/system/auxiliary/custom/custom.api';
import { apiGetGradeDropdown } from '@/api/http/system/auxiliary/grade/grade.api';
import { userRemarkFormItem, userStatusFormItem } from '@/settings/ShareFormItem';
import { apiGetDeptsDropdown } from '@/api/http/system/senior/depts/depts.api';

export const useCustomerUpdateSchemaForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '客户名称', component: 'Input' },
    { field: 'py', label: '拼音', component: 'Input', show: false },
    { field: 'number', label: '客户编号', component: 'Input' },
    {
      field: 'deptId',
      label: '组织结构',
      component: 'ApiTreeSelect',
      componentProps: { api: apiGetDeptsDropdown },
    },
    {
      field: 'userId',
      label: '所属用户',
      component: 'NodList',
      componentProps: ({ formModel }) => {
        return {
          scene: 'user',
          initTitle: formModel['nickname'],
        };
      },
    },
    {
      field: 'crgId',
      label: '客户类别',
      component: 'ApiSelect',
      componentProps: { api: apiGetCustomDropdown },
    },
    {
      field: 'gradeId',
      label: '客户等级',
      component: 'ApiSelect',
      componentProps: { api: apiGetGradeDropdown },
    },
    { field: 'bank', label: '开户银行', component: 'Input' },
    { field: 'account', label: '银行账号', component: 'Input' },
    { field: 'tax', label: '纳税号码', component: 'Input' },

    // { field: 'contacts', label: '联系人', component: 'Input', show: false },

    { field: 'more', label: '扩展信息', component: 'Input', show: false },
    userStatusFormItem(),
    userRemarkFormItem(),
    { field: 'id', label: '客户id', component: 'Input', show: false },
    { field: 'nickname', label: '供应商id', component: 'Input', show: false },
  ];
};

export const useCustomerListColumns = (): BasicColumn[] => {
  return [
    { title: 'ID', dataIndex: 'id', ifShow: false },
    { title: '客户名称', dataIndex: 'name' },
    { title: '客户编号', dataIndex: 'number' },
    { title: '所属组织', dataIndex: 'deptName' },
    { title: '所属用户', dataIndex: 'nickname' },
    { title: '客户类别', dataIndex: 'crgName' },
    { title: '客户等级', dataIndex: 'gradeName' },

    { title: '应收款余额', dataIndex: 'balance' },
    { title: '客户积分', dataIndex: 'integral' },

    userStatusColumn(),
    userRemarksColumn(),
  ];
};

export const useCustomerListSearchForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '客户名称', component: 'Input' },
    { field: 'number', label: '客户编号', component: 'Input' },
    {
      field: 'crgId',
      label: '客户类别',
      component: 'ApiSelect',
      componentProps: {
        api: apiGetCustomDropdown,
      },
    },
    {
      field: 'gradeId',
      label: '客户等级',
      component: 'ApiSelect',
      componentProps: { api: apiGetGradeDropdown },
    },
  ];
};
